草庐IT

android - asyncTask 测试不执行

全部标签

javascript - Angular:使用 MockBackend 测试 HTTP,真的需要 async() 吗?

我正在使用MockBackend来测试依赖于@angular/http的代码。网络上的所有示例都使用异步测试设置,如下所示:thoughtram:TestingServiceswithHttpinAngulardescribe('getVideos()',()=>{it('shouldreturnanObservable>',async(inject([VideoService,MockBackend],(videoService,mockBackend)=>{videoService.getVideos().subscribe((videos)=>{expect(videos.len

javascript - 使用 chrome.tabs.executeScript 执行异步函数

我有一个功能,我想使用chrome.tabs.executeScript在页面中执行,从浏览器操作弹出窗口运行。权限设置正确,并且可以正常使用同步回调:chrome.tabs.executeScript(tab.id,{code:`(function(){//Dolotsofthingsreturntrue;})()`},r=>console.log(r[0]));//Logstrue问题是我要调用的函数要经过几个回调,所以我想使用async和await:chrome.tabs.executeScript(tab.id,{code:`(asyncfunction(){//Dolotso

javascript - 如何使用 Angular 2/4 的鼠标滚轮事件测试指令

我有一个带有鼠标滚轮事件的指令,它用于放大和缩小Canvas。我想知道如何为此类事件编写单元测试。我在网上找不到任何示例,谁能给我指出正确的方向?我的指令:import{Directive,ElementRef,HostListener}from"@angular/core";import{MyService}from"./my-service";@Directive({selector:"[testDirec]"})exportclassTest{privateinitPointX:number;privateinitPointY:number;constructor(private

javascript - Node.js setImmediate 在 I/O 回调之前执行(事件循环)

看看下面的代码:varfs=require('fs');varpos=0;fs.stat(__filename,function(){console.log(++pos+"FIRSTSTAT");});fs.stat(__filename,function(){console.log(++pos+"LASTSTAT");});setImmediate(function(){console.log(++pos+"IMMEDIATE")})当我执行这段代码时,会显示以下结果:作为Node.jsdocumentation解释一下,setImmediate是在I/O回调之后执行的,但是在这个例

javascript - Sinon - stub 模块功能并在没有依赖注入(inject)的情况下对其进行测试

我有一个代理模块,它将函数调用转发给服务。当调用此代理模块中的函数时,我想测试是否调用了服务函数。这是代理模块:constpayService=require('../services/pay')constwalletService=require('../services/wallet')constentity={chargeCard:payService.payByCardToken,//...someotherfn}module.exports=entity基于thisexample和thisresponse,我试图stub所需的模块“payService”:constexpec

javascript - promise 中的超时循环在 promise 解决后永远不会执行?

我遇到了一个问题,即从已解决的promise发送到setTimeout的回调永远不会执行。假设我有以下内容:classFoo{constructor(foo){this.foo=foo;}asyncexecUntilStop(callback){consttimeoutLoopCallback=()=>{if(this.stopExec)return;callback({data:'data'});setTimeout(timeoutLoopCallback,10);};setTimeout(timeoutLoopCallback,10);return{data:'data'};}st

javascript - Observable 对多个订阅者执行一次

我有一段代码要定期执行,直到所有订阅者都取消订阅。//Thisfunctionshallbecalled*once*pertick,//nomatterthequantityofsubscriber.functiondoSomething(val){console.log("doingsomething");returnval;}observable=Rx.Observable.timer(0,1000).map(val=>doSomething(val));constfirst=observable.subscribe(val=>console.log("first:",val));

javascript - jest mockgoose - jest 在测试运行完成后一秒钟没有退出

我有一个Mongoose模型:varmongoose=require("mongoose");vartransactionSchema=mongoose.Schema({category:{type:String,required:[true,"Categoryisrequired."]},amount:Number,comment:String,tags:Array,currency:String});varTransaction=mongoose.model("Transaction",transactionSchema);module.exports=Transaction;以及

javascript - --skip-js-errors 特定测试用例

我正在测试包括重定向到我无法控制的外部页面的功能。此页面正在抛出导致测试失败的错误。有没有办法只针对一个特定的测试忽略js错误?(我希望我网站上的错误导致测试失败) 最佳答案 目前,TestCafe不允许这样做。我创建了一个proposal在您的用例的TestCafe存储库中。跟踪它以了解进度。更新:有一个example演示了如何扩展内置错误跟踪功能并通过谓词函数跳过JavaScript错误。 关于javascript---skip-js-errors特定测试用例,我们在StackOve

javascript - 对 JavaScript 中的递归和执行流程有更清晰的解释吗?

我在阅读EloquentJavaScript时遇到了这个谜题示例:Considerthispuzzle:Bystartingfromthenumber1andrepeatedlyeitheradding5ormultiplyingby3,aninfiniteamountofnewnumberscanbeproduced.Howwouldyouwriteafunctionthat,givenanumber,triestofindasequenceofadditionsandmultiplicationsthatproducethatnumber?这是解决方案的代码:functionfin